package com.factory.absfactory.self.order;

import com.factory.absfactory.self.pizza.Cake;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class OrderCake {

    private AbsFactory absFactory;

    public OrderCake(AbsFactory absFactory) {
        setAbsFactory(absFactory);
    }

    public void setAbsFactory(AbsFactory absFactory) {
        this.absFactory = absFactory;
        Cake cake = null;
        String type = "";
        do {
            type = getType();
            cake = this.absFactory.makeCake(type);
            if(cake!=null){
                cake.prepare();
                cake.ferment();
                cake.cut();
                cake.box();
            }
        }while (true);
    }

    public String getType(){
        try {
            BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(System.in));
            System.out.println("请输入蛋糕类型:");
            String systemIn = bufferedReader.readLine();
            return systemIn;
        } catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }
}
